package com.qf.service;

import com.qf.constant.CacheConstants;
import com.qf.constant.ReportStateConstants;
import com.qf.feign.CacheFeign;
import com.qf.model.StandardSubmit;
import com.qf.util.PushMsgUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * author:z
 * time:2021/12/29 17:22
 * description:黑名单过滤策略
 */
@Service(value = "black")
@Slf4j
public class BlackChainManagerImpl implements FilterChainService {

    @Autowired
    private PushMsgUtil pushMsgUtil;

    @Autowired
    private CacheFeign cacheFeign;

    @Override
    public boolean strategy(StandardSubmit standardSubmit) {
        log.info("[策略模块-黑名单策略]开始执行！");
        //获取黑名单用户
        String blackPhone = cacheFeign.get(CacheConstants.CACHE_PREFIX_BLACK + standardSubmit.getDestMobile());
        //判断黑名单用户是否为空
        //判断发送短信的手机号是否存在黑名单中
        if ("1".equals(blackPhone)) {
            //如果存在黑名单中 发送短信失败
            pushMsgUtil.pushReport(standardSubmit, String.valueOf(ReportStateConstants.FAIL));
            log.info("[策略模块-黑名单策略]，短信发送失败，账户存在黑名单中！blackPhone={}", standardSubmit.getDestMobile());
            pushMsgUtil.sendLog(standardSubmit, String.valueOf(ReportStateConstants.FAIL));
            return false;
        }

        log.info("[策略模块-黑名单策略]执行结束！");
        return true;
    }
}
